<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css" />
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>
        #auto_p{
            position: relative;
        }
        #auto{
            position: absolute;
            top: 21px;
            right: 182px;
            z-index:999;
        }
    </style>
</head>

<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">提现单号:</div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="outRequestNo"  placeholder="请输入搜索内容" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">用户名:</div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="userName"  placeholder="请输入搜索内容" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">审核提现方式:</div>
                <div class="layui-form-item layui-inline">

                    <div>
                        <select name="withdrawalType" lay-verify="" style="width: 200px;">
                            <option value="">请选择审核提现方式</option>
                            <option value="1">微信</option>
                            <option value="2">支付宝</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">提现状态:</div>
                <div class="layui-form-item layui-inline">
                    <div>
                        <select name="status" lay-verify="" style="width: 200px;">
                            <option value="">请选提现状态</option>
                            <option value="1">待审核</option>
                            <option value="2">后台拒绝提现</option>
                            <option value="3">提现成功</option>
                            <option value="4">提现失败(</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">开始日期:</div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="startTime" placeholder="请选择日期">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">结束日期:</div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="endTime" placeholder="请选择日期">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="yhxx-query">
                        <i class="layui-icon layui-icon-search"></i>
                        搜索
                    </button>
                </div>

            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div id="auto_p" class="layui-card-body">
        <form id = "auto" class="layui-form" >
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input id = "autoBox" type="checkbox" name="isAuto"  lay-filter="auto"title="自动审核" />
                </div>
            </div>
        </form>
        <table id="yhxx-table" lay-filter="yhxx-table"></table>
    </div>
</div>
<script type="text/html" id="startTime_tpl">
    {{layui.util.toDateString(d.startTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script type="text/html" id="endTime-tpl">
    {{layui.util.toDateString(d.endTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script type="text/html" id="withdrawal-bar">
    {{#if(d != 2) { }}
    <!--<button class="pear-btn pear-btn-sm" lay-event="retract">撤回</button>-->
    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="pass">通过</button>
    <button type="button" class="pear-btn pear-btn-danger pear-btn-sm" lay-event="refuse">拒绝</button>
    {{#} }}
</script>

<script type="text/html" id="avatar-tpl">
    <img src="{{d.avatar}}"/>
</script>

<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    var  d, checkboxValue;
    layui.use(['table', 'laydate', 'form', 'jquery'], function () {
        //alert($("#autoBox").checked)
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        var laydate = layui.laydate;
        //年月选择器
        laydate.render({
            elem: '#startTime'

        });
        laydate.render({
            elem: '#endTime',
            min:$("#startTime").val()
        });

        let cols = [
            [{
                type: 'checkbox'
            },
                {
                    title: '序号',
                    field: 'id',
                    align: 'center',
                    width: 100
                },
                {
                    title: '提现单号',
                    field: 'outRequestNo',
                    align: 'center'
                },
                {
                    title: '用户',
                    field: 'userName',
                    align: 'center'
        /*            templet: function (data) {
                        if (data.type == 0) {
                            return '<span>单聊</span>'
                        } else if (data.type == 1) {
                            return '<span>群聊</span>'
                        } else if (data.type == 2) {
                            return '<span>聊天室</span>'
                        } else {
                            return '<span>频道</span>'
                        }*/

                },
                {
                    title: '审核提现方式',
                    field: 'withdrawalType',
                    align: 'center',

                },
                {
                    title: '提现金额',
                    field: 'amount',
                    align: 'center',
                },
                {
                    title: '提现状态',
                    field: 'withdrawalStatus',
                    align: 'center',
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    templet: "#createTime-tpl"
                },
                {
                    title: '操作',
                    field:'statusCode',
                    toolbar: '#withdrawal-bar',
                    align: 'center',
                    width: 130,
                }
            ]
        ]

        //给CheckBox赋值
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                url: "/api/wthdrawal/selectAutoCode",
                success: function (result) {
                    if (result.code == 200) {
                        var unitTypeCheckbox = $("input[id='autoBox']");
                        console.log(unitTypeCheckbox);
                        if (result.result == 1) {
                            unitTypeCheckbox.attr("checked","");
                        } else {
                            unitTypeCheckbox.removeAttr("checked");
                        }
                        form.render();
                    }

                }
        });
        });

        table.render({
            elem: '#yhxx-table',
            url: '/api/wthdrawal/select',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#yhxx-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            done:function (res,curr,count) {
                for (var i=0;i<res.data.length;i++)
                {
                    if(res.data[i].statusCode != 1){
                        $('table[class="layui-table"]').
                        find('tr[data-index="' + i + '"]').
                        find('td[data-field="statusCode"]').
                        html('<div>操作完毕</div>')
                    }
                }
                
            }
        });

        table.on('tool(yhxx-table)', function (obj) {
            if (obj.event === 'pass') {
                window.pass(obj);
            } else if (obj.event === 'refuse') {
                window.refuse(obj);
            }
        });

        table.on('toolbar(yhxx-table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        form.on('submit(yhxx-query)', function (data) {
            data.field.createTime = $("#createTime").val();
            console.log(JSON.stringify(data))
            table.reload('yhxx-table', {
                where: data.field
            })
            return false;
        });

        form.on('switch(yhxx-enable)', function (obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
        });

        window.pass = function (obj) {
            layer.confirm('确定要通过该提现订单吗',
                {icon:3,title:'提示'},
                function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: "/api/wthdrawal/checkWithdrawal/" + obj.data.withdrawalId + "/1",
                        dataType: 'json',
                        success: function (result) {
                            layer.close(loading);
                            if (result.code == 200) {
                                layer.msg(result.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('yhxx-table');
                                });
                            } else {
                                layer.msg(result.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                })
        }
        window.refuse = function (obj) {
            layer.confirm('确定要拒绝该提现订单吗',{icon:3,title:'提示'},function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/api/wthdrawal/checkWithdrawal/" + obj.data.withdrawalId + "/2" ,
                    dataType: 'json',
                    success: function (result) {
                       layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('yhxx-table');
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            })
        }
       /* window.retract = function (obj) {

            layer.confirm('确定要撤回本条消息吗？', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/api/messages/retract/" + obj.data.fromID + "/" + obj.data.mid,
                    dataType: 'json',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                table.reload('yhxx-table');
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }*/


        window.refresh = function (param) {
            table.reload('yhxx-table');
        }
        form.on('checkbox(auto)', function (data) {
            var status;
            if(data.elem.checked ){
                status = 1;
            }else {
                status = 0;
            }
            $.ajax({
                url: "/api/wthdrawal/autoWithdrawal/" + status  ,
                dataType: 'json',
                success: function (result) {
                    //layer.close(loading);
                    if (result.code == 200) {
                        var unitTypeCheckbox = $("input[id='autoBox']");
                        if (status == 1) {
                            unitTypeCheckbox.attr("checked","");
                        }
                        else {
                            unitTypeCheckbox.removeAttr("checked");
                        }
                        form.render();
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    });
    // function getAutoValue() {
    //     $.ajax({
    //         url: "http://localhost:8081/wthdrawal/se/" + status  ,
    //         dataType: 'json',
    //         success: function (result) {
    //             if (result.code == 200) {
    //                checkboxValue = result;
    //             }
    //         }
    //     })
    // }
</script>
</body>

</html>